

package com.idcos.enterprise.portal.web.auto;

// auto generated imports

import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.idcos.cloud.biz.common.permisson.OperateAction;
import com.idcos.cloud.web.common.BaseResultVO;
import com.idcos.cloud.web.common.JsonResultUtil;
import com.idcos.enterprise.portal.form.PortalQueryByPageForm;
import com.idcos.enterprise.portal.form.PortalRoleCreateForm;
import com.idcos.enterprise.portal.form.PortalRoleQueryByPageForm;
import com.idcos.enterprise.portal.form.PortalRoleUpdateForm;
import com.idcos.enterprise.portal.manager.auto.PortalRoleOperateManager;
import com.idcos.enterprise.portal.manager.auto.PortalRoleQueryManager;

/**
 * 角色管理
 * web层controller相关的接口自动生成，此文件属于自动生成的，请勿直接修改,具体可以参考codegen工程
 * Generated by <tt>controller-codegen</tt> on 2015-10-30 15:00:49.
 *
 * @author jiaohuizhe
 * @version PortalRoleController.java, v 1.1 2015-10-30 15:00:49 jiaohuizhe Exp $
 */

@Controller
@OperateAction("F_PORTAL_ROLE")
@RequestMapping(value = "/portal/role")
@Api(tags = "07.角色管理的接口", description = "PortalRoleController")
public class PortalRoleController {

    //========== manager ==========

    @Autowired
    private PortalRoleQueryManager portalRoleQueryManager;

    @Autowired
    private PortalRoleOperateManager portalRoleOperateManager;

    /**
     * 分配用户组
     *
     * @param id
     * @param selGroups
     * @return BaseResultVO
     */
    @RequestMapping(method = RequestMethod.POST, value = "/{id}/allocate/group")
    @ResponseBody
    @OperateAction("O_PORTAL_ROLE_POST")
    public BaseResultVO allocateGroup(@PathVariable String id,
                                      @RequestParam("selGroups") String selGroups) {
        return JsonResultUtil.getResult(portalRoleOperateManager.allocateGroup(id, selGroups));

    }

    /**
     * 获取某个角色信息
     *
     * @param id
     * @return BaseResultVO
     */
    @RequestMapping(method = RequestMethod.GET, value = "/{id}")
    @ResponseBody
    @OperateAction("O_PORTAL_ROLE_GET")
    public BaseResultVO queryById(@PathVariable String id) {
        return JsonResultUtil.getResult(portalRoleQueryManager.queryById(id));

    }

    /**
     * 获取某个角色用户信息
     *
     * @param id
     * @return BaseResultVO
     */
    @RequestMapping(method = RequestMethod.GET, value = "/users/{id}")
    @ResponseBody
    @OperateAction("O_PORTAL_ROLE_GET")
    public BaseResultVO queryUsersById(@PathVariable String id) {
        return JsonResultUtil.getResult(portalRoleQueryManager.queryUsersById(id));

    }

    /**
     * 获取某个角色用户组信息
     *
     * @param id
     * @return BaseResultVO
     */
    @RequestMapping(method = RequestMethod.GET, value = "/groups/{id}")
    @ResponseBody
    @OperateAction("O_PORTAL_ROLE_GET")
    public BaseResultVO queryGroupsById(@PathVariable String id) {
        return JsonResultUtil.getResult(portalRoleQueryManager.queryGroupsById(id));

    }

    /**
     * 获取某个角色权限信息
     *
     * @param id
     * @return BaseResultVO
     */
    @RequestMapping(method = RequestMethod.GET, value = "/permissions/{id}")
    @ResponseBody
    @OperateAction("O_PORTAL_ROLE_GET")
    public BaseResultVO queryPermissionsById(@PathVariable String id) {
        return JsonResultUtil.getResult(portalRoleQueryManager.queryPermissionsById(id));

    }

    /**
     * 删除角色信息
     *
     * @param id
     * @return BaseResultVO
     */
    @RequestMapping(method = RequestMethod.DELETE, value = "/{id}")
    @ResponseBody
    @OperateAction("O_PORTAL_ROLE_DELETE")
    public BaseResultVO delete(@PathVariable String id) {
        return JsonResultUtil.getResult(portalRoleOperateManager.delete(id));

    }

    /**
     * 更新角色信息
     *
     * @param id
     * @param form
     * @return BaseResultVO
     */
    @RequestMapping(method = RequestMethod.PUT, value = "/{id}")
    @ResponseBody
    @OperateAction("O_PORTAL_ROLE_UPDATE")
    public BaseResultVO update(@PathVariable String id, PortalRoleUpdateForm form) {
        return JsonResultUtil.getResult(portalRoleOperateManager.update(id, form));

    }

    /**
     * 查询角色信息
     *
     * @param offset
     * @param limit
     * @param form
     * @return BaseResultVO
     */
    @RequestMapping(method = RequestMethod.GET, value = "/page/{offset}/{limit}")
    @ResponseBody
    @OperateAction("O_PORTAL_ROLE_PAGE")
    public BaseResultVO queryByPage(@PathVariable String offset, @PathVariable String limit,
                                    PortalRoleQueryByPageForm form) {
        return JsonResultUtil.getResult(portalRoleQueryManager.queryByPage(offset, limit, form));

    }

    /**
     * 创建角色信息
     *
     * @param form
     * @return BaseResultVO
     */
    @RequestMapping(method = RequestMethod.POST, value = "/")
    @ResponseBody
    @OperateAction("O_PORTAL_ROLE_CREATE")
    public BaseResultVO create(PortalRoleCreateForm form) {
        return JsonResultUtil.getResult(portalRoleOperateManager.create(form));

    }

    /**
     * 查询用户组所关联的角色信息
     *
     * @param id
     * @return BaseResultVO
     */
    @RequestMapping(method = RequestMethod.GET, value = "/page/group")
    @ResponseBody
    @OperateAction("O_PORTAL_ROLE_GET")
    public BaseResultVO queryRolePageByGroupIdAndCnd(PortalQueryByPageForm form) {
        return JsonResultUtil.getResult(portalRoleQueryManager.queryRolePageByGroupIdAndCnd(form));
    }

    /**
     * 查询用户所关联的角色信息
     *
     * @param id
     * @return BaseResultVO
     */
    @RequestMapping(method = RequestMethod.GET, value = "/page/user")
    @ResponseBody
    @OperateAction("O_PORTAL_ROLE_GET")
    public BaseResultVO queryRolePageByUserIdAndCnd(PortalQueryByPageForm form) {
        return JsonResultUtil.getResult(portalRoleQueryManager.queryRolePageByUserIdAndCnd(form));
    }

}
